package spt.slides;

import java.sql.Timestamp;

import spt.exceptions.ValidationException;

public class Slide {
	private int id;
	private String content;
	private Timestamp publishStart;
	private Timestamp publishStop;
	private int displayTime;
	private boolean alwaysPublished;
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getContent() {
		return content;
	}
	
	public void setContent(String content) {
		this.content = content;
	}
	
	public Timestamp getPublishStart() {
		return publishStart;
	}
	
	public void setPublishStart(Timestamp publishStart) {
		this.publishStart = publishStart;
	}
	
	public Timestamp getPublishStop() {
		return publishStop;
	}
	
	public void setPublishStop(Timestamp publishStop) {
		this.publishStop = publishStop;
	}
	
	public int getDisplayTime() {
		return displayTime;
	}
	
	public void setDisplayTime(int displayTime) {
		this.displayTime = displayTime;
	}
	
	public boolean isAlwaysPublished() {
		return alwaysPublished;
	}
	
	public void setAlwaysPublished(boolean alwaysPublished) {
		this.alwaysPublished = alwaysPublished;
	}
	
	public void validate() throws ValidationException{
		if(content == null || content.isEmpty())
			throw new ValidationException("Content is empty.");
		
		if(publishStart != null && publishStop != null)
			if(publishStart.after(publishStop))
				throw new ValidationException("Incorrect publish dates.");
		
		if(!alwaysPublished && (publishStart == null || publishStop == null))
			throw new ValidationException("Publish dates were not specified.");
		
		if(displayTime <= 0)
			throw new ValidationException("Incorrect display time.");
	}
	
	@Override
	public String toString() {
		return "Slide [id=" + id + ", content=" + content + ", publishStart="
				+ publishStart + ", publishStop=" + publishStop
				+ ", displayTime=" + displayTime + ", alwaysPublished="
				+ alwaysPublished + "]";
	}
}
